﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;

namespace WindowsPhoneApplication1
{

    public partial class recommendedPage : PhoneApplicationPage
    {

        IsolatedStorageSettings trkData = IsolatedStorageSettings.ApplicationSettings;
        
        public recommendedPage()
        {
            InitializeComponent();
        }

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            List<Track> trackList = new List<Track>();
            trackList.Add(new Track("yahudia", "ramat hagolan", "hard", "no", 35.7028, 32.9416, "Images/waterfall_pool.jpg", "bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla "));
            trackList.Add(new Track("beeri", "northern negev", "easy", "yes", 34.5543, 31.5063, "Images/beeri.jpg", "bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla "));
            
            RecList.ItemsSource = trackList;
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Track trk = (sender as Button).DataContext as Track;
            ListBoxItem pressedItem = this.RecList.ItemContainerGenerator.ContainerFromItem(trk) as ListBoxItem;
            
            if (pressedItem != null)
            {

                if (!trkData.Contains("name"))
                    trkData.Add("name", trk.Name);
                else
                    trkData["name"] = trk.Name;

                if (!trkData.Contains("location"))
                    trkData.Add("location", trk.Loc);
                else
                    trkData["location"] = trk.Loc;

                if (!trkData.Contains("difficulty"))
                    trkData.Add("difficulty", trk.Diff);
                else
                    trkData["difficulty"] = trk.Diff;

                if (!trkData.Contains("accessibility"))
                    trkData.Add("accessibility", trk.Acc);
                else
                    trkData["accessibility"] = trk.Acc;
                
                if (!trkData.Contains("longitude"))
                    trkData.Add("longitude",trk.Longi);
                else
                    trkData["longitude"] = trk.Longi;

                if (!trkData.Contains("latitude"))
                    trkData.Add("latitude", trk.Lati);
                else
                    trkData["latitude"] = trk.Lati;

                if (!trkData.Contains("picPath"))
                    trkData.Add("picPath", trk.Pic);
                else
                    trkData["picPath"] = trk.Pic;

                if (!trkData.Contains("discription"))
                    trkData.Add("discription", trk.Discr);
                else
                    trkData["description"] = trk.Discr;

                trkData.Save();

                NavigationService.Navigate(new Uri("/trackPage.xaml", UriKind.RelativeOrAbsolute));
            }
        }

        private void OnBackKeyPress(object sender, System.ComponentModel.CancelEventArgs e)
        {
            trkData.Remove("name");
            trkData.Remove("location");
            trkData.Remove("difficulty");
            trkData.Remove("accessibility");
            trkData.Remove("longitude");
            trkData.Remove("latitude");
            trkData.Remove("picPath");

        } 

    }

    public class Track
    {

        public String Name { get; set; }
        public String Loc { get; set; }
        public String Diff { get; set; }
        public String Acc { get; set; }
        public double Longi { get; set; }
        public double Lati { get; set; }
        public String Pic { get; set; }
        public String Discr { get; set; }

        public Track(String name, String loc, String diff, String acc, double longi, double lati, String pic, String discr)
        {
            this.Name = name;
            this.Loc = loc;
            this.Diff = diff;
            this.Acc = acc;
            this.Longi = longi;
            this.Lati = lati;
            this.Pic = pic;
            this.Discr = discr;
        }

    }

}